class Solution:
    def maxSubArray(self, nums: list[int]) -> int:
        temp = nums[0]
        res = -2147483648
        for i in range(1, len(nums)):
            res = max(res, temp)
            if temp < 0:
                temp = nums[i]
            else:
                temp += nums[i]
        return max(res, temp)
